﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DVSProject.Lib;
using DVSProject.Models;

namespace DVSProject.Controllers
{
    public class SignagesRemarkController : Controller
    {
        //
        // GET: /SignagesRemark/

        public ActionResult Index()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
            IEnumerable<SignagesRemarkModels> _SignagesRemarks = _SignagesRemarkRepo.GetSignagesRemark();
            return View(_SignagesRemarks);
        }

        //
        // GET: /SignagesRemark/Details/5

        public ActionResult Details(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
            SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();
            _SignagesRemark = _SignagesRemarkRepo.GetSignagesRemarkById(id);
            return View(_SignagesRemark);
        }

        //
        // GET: /SignagesRemark/Create

        public ActionResult Create()
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            return View();
        } 

        //
        // POST: /SignagesRemark/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add insert logic here
                SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
                SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();

                _SignagesRemark.SignagesRemarkTh = collection["SignagesRemarkTh"];
                _SignagesRemark.SignagesRemarkEng = collection["SignagesRemarkEng"];
                _SignagesRemark.CreateBy = (string)Session["User"];
                bool result = _SignagesRemarkRepo.Create(_SignagesRemark);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /SignagesRemark/Edit/5
 
        public ActionResult Edit(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
            SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();
            _SignagesRemark = _SignagesRemarkRepo.GetSignagesRemarkById(id);
            return View(_SignagesRemark);
        }

        //
        // POST: /SignagesRemark/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add update logic here
                SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
                SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();
                _SignagesRemark.Id = id;
                _SignagesRemark.SignagesRemarkTh = collection["SignagesRemarkTh"];
                _SignagesRemark.SignagesRemarkTh = collection["SignagesRemarkTh"];
                _SignagesRemark.UpdateBy = (string)Session["User"];
                bool result = _SignagesRemarkRepo.Edit(_SignagesRemark);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /SignagesRemark/Delete/5
 
        public ActionResult Delete(int id)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
            SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();
            _SignagesRemark = _SignagesRemarkRepo.GetSignagesRemarkById(id);
            return View(_SignagesRemark);
        }

        //
        // POST: /SignagesRemark/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            if (Session["User"] == null) { return RedirectToAction("LogOn", "Account"); }
            try
            {
                // TODO: Add delete logic here

                SignagesRemarkRepo _SignagesRemarkRepo = new SignagesRemarkRepo();
                SignagesRemarkModels _SignagesRemark = new SignagesRemarkModels();
                _SignagesRemark.Id = id;
                _SignagesRemark.UpdateBy = (string)Session["User"];
                bool result = _SignagesRemarkRepo.Delete(_SignagesRemark);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
